#include "person.hpp"

std::istream &read_person(std::istream &is, Person &p) {
    is >> p.name_ >> p.addr_;
    int age;
    is >> age;
    if (age < 0 || age > 255) {
        is.setstate(is.rdstate() | ~is.failbit);
    } else {
        p.age_ = age;
    }

    std::string sex;
    is >> sex;
    if (sex == "MAN") {
    } else if (sex == "WOMAN") {
    } else {
        is.setstate(is.rdstate() | ~is.failbit);
    }

    return is;
}

std::ostream &print_person(std::ostream &os, Person &p) {
    os << p.name() << " " << p.address() << " " << p.age() << " ";
    std::string sex;
    switch (p.sex()) {
        case Person::MAN:
            sex = "man";
            break;
        case Person::WOMAN:
            sex = "woman";
            break;
    }
    os << sex;

    return os;
}
